<#include "common.ftl">
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${_daofullname}">

    <resultMap id="SelectAllResult" type="${_cfullname}"> 
    	<id property="${obj.primaryKey}" column="${obj.jdbcPK}"/>
    	<#list obj.props as prop> 
    	<result property="${prop.name}" column="${prop.columnName}" jdbcType="${prop.jdbcType}" javaType="${prop.type}" /> 
    	</#list>
    </resultMap> 
    
    <parameterMap id="Params" type="${_cfullname}"> 
    	<#list obj.props as prop> 
    	<parameter property="${prop.name}" jdbcType="${prop.jdbcType}" javaType="${prop.type}" /> 
    	</#list>
    </parameterMap>
    
    <sql id="allFields">
    	<#list obj.props as prop> 
			${prop.columnName}<#if prop_has_next>,</#if>
		</#list>
    </sql>

	<insert id="insert${_cname}" parameterMap="Params">
		insert into ${obj.tableName} (<include refid="allFields"/>)
		values (
		<#list obj.props as prop> 
			#${_brack}${prop.name}}<#if prop_has_next>,</#if>
		</#list>
		)
	</insert>
	
	<delete id="delete${_cname}ById">
		delete from ${obj.tableName} where ${obj.jdbcPK} = #${_brack}${obj.primaryKey}}
	</delete>
	
	<update id="update${_cname}" parameterMap="Params">
		 update ${obj.tableName} 
		    set	
				<#list obj.props as prop> 
				${prop.columnName} = #${_brack}${prop.name}}<#if prop_has_next>,</#if>
				</#list>
		  where ${obj.jdbcPK} = #${_brack}${obj.primaryKey}}
	</update>
	
	<select id="get${_cname}" resultMap="SelectAllResult" parameterType="String" >
		select <include refid="allFields"/> 
		  from ${obj.tableName} 
		 where ${obj.jdbcPK} = #${_brack}${obj.primaryKey}} 
	</select>
    
</mapper>    